from AgropurBTFunctions import *
counter = True
while counter:
    print('*******************************')
    print('*            MENU             *')
    print('*Choice of commodity to hedge *')
    print('*******************************')
    print('* 1. Sugar #11                *')
    print('* 2. Dry Whey                 *')
    print('* 3. Non Fat Dry Milk         *')
    print('* 4. Class III Milk           *')
    print('*******************************')
    print('* 0. Quit                     *')
    print('*******************************')
    choices = [0,1,2,3,4]   
    yourchoice = 6
    while yourchoice not in choices:
        yourchoice = int(input('Your Choice:'))
    if yourchoice == 0:
        break
    if yourchoice== 1:
        filename = 'SUGAReff.csv'
        echeance = 8
        ticker = 'GY'
    elif yourchoice ==2:
        filename = 'WHEYeff.csv'
        echeance = 12
        ticker = 'DY'
    elif yourchoice == 3:
        filename = 'NFDMeff.csv'
        echeance = 12
        ticker = 'GNF'
    elif yourchoice == 4:
        filename = 'CLASS3eff.csv'
        echeance = 12
        ticker='DC'
    if filename == 'SUGAReff.csv':
        comm = True
    else:
        comm = False
    try:
        print('Constructing database....')
        hi = efficientDataframe(filename, echeance)
        print('Done...')                
    except FileNotFoundError:
        print("File Not Found! Try again!")
    
    
    while True:
        print('*****************************************')
        print('*                  MENU                 *')
        print('*       Choice of BackTest to run       *')
        print('*****************************************')
        print('* 1. Lock and Hold, Fixed holding period*')
        print('* 2. Trade relying on moving average    *')
        print('* 3. Choose New Commodity               *')
        print('*****************************************')
        print('* 0. Quit                               *')
        print('*****************************************')
        btchoice = [0,1,2,3]
        testerChoice = 5
        while testerChoice not in btchoice:
            testerChoice = int(input("Your Choice:"))
        if not testerChoice or testerChoice ==3:
            break
        elif testerChoice == 1:
            rollMonth = 30
            while rollMonth > echeance or rollMonth <= 0:
                rollMonth = int(input("Entrez le numero du contrat a rouler: "))
            hedge = -1
            while hedge > 1 or hedge < 0:
                hedge = float(input("Entrez le ratio de couverture [0,1]: "))
            BT = lockNHoldEfficient(hi,rollMonth,hedge,ticker,comm)
        elif testerChoice == 2:
            highMonth = 0
            while highMonth > echeance or highMonth <= 0:
                highMonth = int(input("Enter number of contract to buy when price over MovingAverage:"))
            lowMonth = 0
            while lowMonth > echeance or lowMonth <= 0:
                lowMonth = int(input("Enter number of contract to buy when price under MovingAverage:"))
            hedge = -1
            while hedge > 1 or hedge < 0:
                hedge = float(input("Enter wanted hedge ratio [0,1]: "))    
            ma = -1
            while ma<0 or ma>2000:
                ma = int(input("Enter number of days for moving average to be calculated:"))
            BTtwo=movingAvgEfficient(hi, ticker, highMonth, lowMonth, hedge, ma, comm)
    if not testerChoice:
        counter = False